package net.mihome.app.utils;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmoticonsUtils {

	/**
	 * @param args
	 * 琛ㄦ儏宸ュ叿銆傚皢濡傦細[23]鏇挎崲鎴愮浉搴旂殑琛ㄦ儏
	 */
	public final static Pattern WECHAT_REG = Pattern.compile("\\[\\d{1,5}\\]");
	public final static String TEMPLE_STRING="<img src=\"{0}\" alt=\"{0}\">";

	public static String filterWechat(String linktxt) {

		if (null == linktxt)
			return linktxt;
		try {
			Matcher match = WECHAT_REG.matcher(linktxt);
			if (null == match)
				return linktxt;
			while (match.find()) {
				String target = match.group();
				if(target!=null){
					Integer targetNum=Integer.parseInt(target.replaceAll("\\[|\\]", ""));
                    if(targetNum!=null){
                        targetNum=targetNum+1;
                    }
					String targetNum2Str="f"+String.format("%03d", targetNum);
					String[] tars=new String[]{new String(targetNum2Str)};
					String tarString=TEMPLE_STRING.replace("{0}",targetNum2Str);
					linktxt = linktxt.replace(target, tarString);
				}
			}
		} catch (Exception e) {
			return linktxt;
		}
		return linktxt;
	}
}
